home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr53
/
pctv4n_1.zip
/
WLIST.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-10
|
4KB
|
125 lines
// Text file lister -- MDI Windows application by Tom Swan
#include <commdlg.h>
#include <owl.h>
#include <mdi.h>
#include "wlist.rch"
#include "status.h"
#include "child.h"
// The MDI application class
class TWListApp: public TApplication {
public:
TWListApp(LPSTR AName, HINSTANCE AnInstance,
HINSTANCE APrevInstance, LPSTR ACmdLine, int ACmdShow)
: TApplication(AName, AnInstance, APrevInstance,
ACmdLine, ACmdShow) {};
virtual void InitMainWindow();
};
// The MDI main window class (the frame)
class TMainWindow: public TMDIFrame {
public:
TMainWindow(LPSTR ATitle, int MenuId);
void ResizeClientRect();
virtual void CMFileOpen(RTMessage)
= [CM_FIRST + CM_MDIFILEOPEN];
virtual void WMSize(RTMessage)
= [WM_FIRST + WM_SIZE];
virtual void WMMenuSelect(RTMessage)
= [WM_FIRST + WM_MENUSELECT];
private:
PTStatusBar pStatusBar; // Pointer to status bar object
char filterStr[BUFSIZE]; // File dialog filter list
int filterIndex; // File dialog filter number
};
// Initialize the MDI application's main (frame) window
void TWListApp::InitMainWindow()
{
MainWindow = new TMainWindow("Text File Viewer", ID_MENU);
}
// Construct main window object
TMainWindow::TMainWindow(LPSTR ATitle, int MenuId)
: TMDIFrame(ATitle, MenuId)
{
filterIndex = 1;
if (LoadString(GetApplication()->hInstance, STR_FILEFILTERS,
filterStr, sizeof(filterStr)) == 0)
filterStr[0] = 0;
else {
int fslen = strlen(filterStr);
for (int i = 0; i < fslen; i++)
if (filterStr[i] == '|')
filterStr[i] = 0;
}
ChildMenuPos = 2;
pStatusBar = new TStatusBar(this);
}
// Send UM_CalcParentClientRect message to child windows
void ResizeChildWindows(Pvoid P, Pvoid Param)
{
HWND hWnd = ((PTWindow)P)->HWindow;
if (hWnd) SendMessage(hWnd,
UM_CalcParentClientRect, FALSE, (LPARAM)Param);
}
// Resize client window rectangle
void TMainWindow::ResizeClientRect()
{
RECT R; // Client rectangle
GetClientRect(HWindow, &R);
ForEach(ResizeChildWindows, &R);
SetWindowPos(ClientWnd->HWindow, 0, R.left, R.top,
R.right - R.left, R.bottom - R.top, SWP_NOZORDER);
}
// Open a file by displaying a common file dialog
void TMainWindow::CMFileOpen(RTMessage)
{
OPENFILENAME fn; // Common dialog structure
char tempName[BUFSIZE]; // Holds filename
memset(&fn, 0, sizeof(fn));
strcpy(tempName, "");
fn.lStructSize = sizeof(OPENFILENAME);
fn.hwndOwner = HWindow;
fn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
fn.lpstrFile = tempName;
fn.nMaxFile = sizeof(tempName);
fn.lpstrFilter = filterStr;
fn.nFilterIndex = filterIndex;
if (GetOpenFileName(&fn)) {
filterIndex = fn.nFilterIndex;
GetApplication()->MakeWindow(new
TChildWindow(this, fn.lpstrFile));
}
}
// Main window size is changing
void TMainWindow::WMSize(RTMessage Msg)
{
TWindow::WMSize(Msg);
if (pStatusBar)
pStatusBar->AdjustSize(Msg.LP.Lo, Msg.LP.Hi);
ResizeClientRect(); // Update client rectangle
}
// Notate menu selections by passing message to child window
void TMainWindow::WMMenuSelect(RTMessage Msg)
{
if (pStatusBar)
SendMessage(pStatusBar->HWindow, WM_MENUSELECT,
Msg.WParam, Msg.LParam);
}
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow)
{
TWListApp WListApp("WListApp", hInstance, hPrevInstance,
lpszCmdLine, nCmdShow);
WListApp.Run();
return WListApp.Status;
}